using System.Collections.Generic;
using OracleInternal.SqlAndPlsqlParser.LocalParsing;

namespace OracleInternal.SqlAndPlsqlParser.RuleProcessors.ODPCommands
{
	internal static class OracleMbEarleyBindVarRuleMultiProcessors
	{
		public static OracleMbEarleyRuleMultiProcessorAddItem[] s_vRuleProcessorItems;

		static OracleMbEarleyBindVarRuleMultiProcessors()
		{
			OracleMbEarleyRuleMultiProcessorAddItem[] array = new OracleMbEarleyRuleMultiProcessorAddItem[5];
			OracleMbEarleyRuleMultiProcessorAddItem oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "bind_var",
				m_vRHSSymbols = new string[1]
				{
					"'?'"
				},
				m_vRuleProcessor = Process_BindVar_QUESTIONMARK_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[0] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "bind_var",
				m_vRHSSymbols = new string[2]
				{
					"':'",
					"digits"
				},
				m_vRuleProcessor = Process_BindVar_COLON_Digits_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[1] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "bind_var",
				m_vRHSSymbols = new string[2]
				{
					"':'",
					"identifier"
				},
				m_vRuleProcessor = Process_BindVar_COLON_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[2] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "data_item",
				m_vRHSSymbols = new string[2]
				{
					"':'",
					"identifier"
				},
				m_vRuleProcessor = Process_BindVar_COLON_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[3] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "bind_var",
				m_vRHSSymbols = new string[4]
				{
					"':'",
					"identifier",
					"'.'",
					"identifier"
				},
				m_vRuleProcessor = Process_BindVar_COLON_Identifier_DOT_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[4] = oracleMbEarleyRuleMultiProcessorAddItem;
			s_vRuleProcessorItems = array;
		}

		public static object Process_BindVar_QUESTIONMARK_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpParserContext oracleLpParserContext = (OracleLpParserContext)ctx;
			OracleLpBindParameter value = null;
			if (!oracleLpParserContext.CurrentStatementBindVarParseNodes.TryGetValue(ctx.CurrentParseNode, out value))
			{
				List<LexerToken> tokens = ctx.Tokens;
				ParseNode currentParseNode = ctx.CurrentParseNode;
				int vBegin = tokens[currentParseNode.From].m_vBegin;
				OracleLpRelativeTextFragment relativeTextFragment = oracleLpParserContext.CurrentStatementText.GetRelativeTextFragment(vBegin, 1);
				OracleLpStatement currentStatement = oracleLpParserContext.CurrentStatement;
				value = new OracleLpBindParameter(currentStatement, relativeTextFragment, ++oracleLpParserContext.CurrentStatementBindVarCount, OracleLpBindParameterType.Positional)
				{
					ParentClause = oracleLpParserContext.CurrentStatementClause
				};
				currentStatement.AddParameter(value);
				oracleLpParserContext.CurrentStatementBindVarParseNodes[ctx.CurrentParseNode] = value;
			}
			return value;
		}

		public static object Process_BindVar_COLON_Digits_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpParserContext oracleLpParserContext = (OracleLpParserContext)ctx;
			OracleLpBindParameter value = null;
			if (!oracleLpParserContext.CurrentStatementBindVarParseNodes.TryGetValue(ctx.CurrentParseNode, out value))
			{
				List<ParseNode> list = ctx.CurrentParseNode.Children();
				List<LexerToken> tokens = ctx.Tokens;
				ParseNode parseNode = list[1];
				int vBegin = tokens[parseNode.From].m_vBegin;
				int vEnd = tokens[parseNode.To - 1].m_vEnd;
				OracleLpRelativeTextFragment relativeTextFragment = oracleLpParserContext.CurrentStatementText.GetRelativeTextFragment(vBegin, vEnd - vBegin);
				OracleLpStatement currentStatement = oracleLpParserContext.CurrentStatement;
				value = new OracleLpBindParameter(currentStatement, relativeTextFragment, ++oracleLpParserContext.CurrentStatementBindVarCount, OracleLpBindParameterType.NamedOrPositional)
				{
					ParentClause = oracleLpParserContext.CurrentStatementClause
				};
				currentStatement.AddParameter(value);
				oracleLpParserContext.CurrentStatementBindVarParseNodes[ctx.CurrentParseNode] = value;
			}
			return value;
		}

		public static object Process_BindVar_COLON_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpParserContext oracleLpParserContext = (OracleLpParserContext)ctx;
			OracleLpBindParameter value = null;
			if (!oracleLpParserContext.CurrentStatementBindVarParseNodes.TryGetValue(ctx.CurrentParseNode, out value))
			{
				List<ParseNode> list = ctx.CurrentParseNode.Children();
				List<LexerToken> tokens = ctx.Tokens;
				ParseNode parseNode = list[1];
				int vBegin = tokens[parseNode.From].m_vBegin;
				int vEnd = tokens[parseNode.To - 1].m_vEnd;
				OracleLpRelativeTextFragment relativeTextFragment = oracleLpParserContext.CurrentStatementText.GetRelativeTextFragment(vBegin, vEnd - vBegin);
				OracleLpStatement currentStatement = oracleLpParserContext.CurrentStatement;
				value = new OracleLpBindParameter(currentStatement, relativeTextFragment, ++oracleLpParserContext.CurrentStatementBindVarCount, OracleLpBindParameterType.NamedOrPositional)
				{
					ParentClause = oracleLpParserContext.CurrentStatementClause
				};
				currentStatement.AddParameter(value);
				oracleLpParserContext.CurrentStatementBindVarParseNodes[ctx.CurrentParseNode] = value;
			}
			return value;
		}

		public static object Process_BindVar_COLON_Identifier_DOT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpParserContext oracleLpParserContext = (OracleLpParserContext)ctx;
			OracleLpBindParameter value = null;
			if (!oracleLpParserContext.CurrentStatementBindVarParseNodes.TryGetValue(ctx.CurrentParseNode, out value))
			{
				List<ParseNode> list = ctx.CurrentParseNode.Children();
				List<LexerToken> tokens = ctx.Tokens;
				int vBegin = tokens[list[1].From].m_vBegin;
				int vEnd = tokens[list[3].To - 1].m_vEnd;
				OracleLpRelativeTextFragment relativeTextFragment = oracleLpParserContext.CurrentStatementText.GetRelativeTextFragment(vBegin, vEnd - vBegin);
				OracleLpStatement currentStatement = oracleLpParserContext.CurrentStatement;
				value = new OracleLpBindParameter(currentStatement, relativeTextFragment, ++oracleLpParserContext.CurrentStatementBindVarCount, OracleLpBindParameterType.NamedOrPositional)
				{
					ParentClause = oracleLpParserContext.CurrentStatementClause
				};
				currentStatement.AddParameter(value);
				oracleLpParserContext.CurrentStatementBindVarParseNodes[ctx.CurrentParseNode] = value;
			}
			return value;
		}
	}
}
